package com.mad.trafficclient;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.mad.trafficclient.login.LoginActivity;
import com.mad.trafficclient.util.LoadingDialog;

public class GuideActivity extends Activity {

    RelativeLayout guide_RL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_guide);
        guide_RL = (RelativeLayout) findViewById(R.id.guide_RL);
        guide_RL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flag();//调用此方法，防止下一次进入不跳转登录界面

                Intent intent = new Intent(GuideActivity.this,
                        LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });

        //**********************
        //如果不是第一次启动直接进入登录界面
        if (isFirst()){
            Intent intent = new Intent(GuideActivity.this,
                    LoginActivity.class);
            startActivity(intent);
            finish();
        }
        //**********************

    }

    //**********************
    //判断是否第一次启动
    private boolean isFirst() {
        SharedPreferences sharedPreferences = getSharedPreferences("guide", MODE_PRIVATE);

        if (sharedPreferences.getBoolean("first", false))
            return true;
        else
            return false;
    }

    //写入标志，证明不是第一次启动
    private void flag(){
        SharedPreferences sharedPreferences = getSharedPreferences("guide", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("first", true).apply();
    }
    //**********************
}
